package cn.findviewbydream.evil.app.websocket

import org.springframework.context.annotation.Configuration
import org.springframework.web.socket.config.annotation.EnableWebSocket
import org.springframework.web.socket.config.annotation.WebSocketConfigurer
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry

/********************************************
 * 工程名：MealOrder
 * 包名：cn.findviewbydream.evil.app.websocket
 * 时间：16-12-25
 * 作者：白雨濃 evil
 * 邮箱：evilbai@foxmail.com
 * 内容：WebSocket设置
 ********************************************/
@Configuration      //指明该类为Spring 配置类
@EnableWebSocket open //声明该类支持WebSocket
class WebSocketConfig : WebSocketConfigurer
{
    override fun registerWebSocketHandlers(registry: WebSocketHandlerRegistry?)
    {
        /*连接地址*/
        /*setAllowedOrigins方法用来设置来自那些域名的请求可访问，默认为localhost*/
        registry?.addHandler(WebSocketHandlerImpl(), "/websocket")
                ?.addInterceptors(HandshakeInterceptor())?.setAllowedOrigins("*")

        /*允许客户端使用sockjs*/
        registry?.addHandler(WebSocketHandlerImpl(), "/sockjs/websocket")
                ?.addInterceptors(HandshakeInterceptor())?.withSockJS()
    }
}